// function.js
Page({
  data: {
    currentCategory: 'massage', // 当前选中的分类
    categoryContent: {
      massage: {
        title: '按摩',
        sections: [
          {
            title: '入门手法',
            icon: '✈️',
            items: [
              { id: 1, title: '压法', image: 'https://images.unsplash.com/photo-1540555700478-4be289fbecef?w=400&h=300&fit=crop', isFree: true, hasPlay: true },
              { id: 2, title: '点法', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: true, hasPlay: true }
            ]
          },
          {
            title: '疾病调理',
            icon: '🏥',
            items: [
              { id: 3, title: '月经不调・按摩疗法', image: 'https://images.unsplash.com/photo-1559757148-5c350d0d3c56?w=400&h=300&fit=crop', isFree: true },
              { id: 4, title: '痛经・按摩疗法', image: 'https://images.unsplash.com/photo-1544367567-0f2fcb009e0b?w=400&h=300&fit=crop', isFree: false }
            ]
          },
          {
            title: '日常保健',
            icon: '👥',
            items: [
              { id: 5, title: '健脾养胃・按摩疗法', image: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=300&fit=crop', isFree: true, hasUpload: true },
              { id: 6, title: '养心安神・按摩疗法', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: false }
            ]
          }
        ]
      },
      moxibustion: {
        title: '艾灸',
        sections: [
          {
            title: '入门手法',
            icon: '✈️',
            items: [
              { id: 1, title: '艾炷灸', image: 'https://images.unsplash.com/photo-1540555700478-4be289fbecef?w=400&h=300&fit=crop', isFree: true, hasPlay: true },
              { id: 2, title: '艾条灸', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: true, hasPlay: true }
            ]
          },
          {
            title: '疾病调理',
            icon: '🏥',
            items: [
              { id: 3, title: '头痛・艾灸疗法', image: 'https://images.unsplash.com/photo-1559757148-5c350d0d3c56?w=400&h=300&fit=crop', isFree: true },
              { id: 4, title: '感冒・艾灸疗法', image: 'https://images.unsplash.com/photo-1544367567-0f2fcb009e0b?w=400&h=300&fit=crop', isFree: false }
            ]
          },
          {
            title: '日常保健',
            icon: '👥',
            items: [
              { id: 5, title: '控油祛痘・艾灸疗法', image: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=300&fit=crop', isFree: true, hasUpload: true },
              { id: 6, title: '养心安神・艾灸疗法', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: false }
            ]
          }
        ]
      },
      cupping: {
        title: '拔罐',
        sections: [
          {
            title: '入门手法',
            icon: '✈️',
            items: [
              { id: 1, title: '常规拔罐疗法', image: 'https://images.unsplash.com/photo-1540555700478-4be289fbecef?w=400&h=300&fit=crop', isFree: true, hasPlay: true },
              { id: 2, title: '闪罐法', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: true, hasPlay: true }
            ]
          },
          {
            title: '疾病调理',
            icon: '🏥',
            items: [
              { id: 3, title: '痛经・拔罐疗法', image: 'https://images.unsplash.com/photo-1559757148-5c350d0d3c56?w=400&h=300&fit=crop', isFree: true },
              { id: 4, title: '不孕症・拔罐疗法', image: 'https://images.unsplash.com/photo-1544367567-0f2fcb009e0b?w=400&h=300&fit=crop', isFree: false }
            ]
          },
          {
            title: '日常保健',
            icon: '👥',
            items: [
              { id: 5, title: '健脾养胃・拔罐疗法', image: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=300&fit=crop', isFree: true, hasUpload: true },
              { id: 6, title: '延年益寿・拔罐疗法', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: false }
            ]
          }
        ]
      },
      guasha: {
        title: '刮痧',
        sections: [
          {
            title: '入门手法',
            icon: '✈️',
            items: [
              { id: 1, title: '角刮痧', image: 'https://images.unsplash.com/photo-1540555700478-4be289fbecef?w=400&h=300&fit=crop', isFree: true, hasPlay: true },
              { id: 2, title: '面刮痧', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: true, hasPlay: true }
            ]
          },
          {
            title: '疾病调理',
            icon: '🏥',
            items: [
              { id: 3, title: '腹泻・刮痧疗法', image: 'https://images.unsplash.com/photo-1559757148-5c350d0d3c56?w=400&h=300&fit=crop', isFree: true },
              { id: 4, title: '高血压・刮痧疗法', image: 'https://images.unsplash.com/photo-1544367567-0f2fcb009e0b?w=400&h=300&fit=crop', isFree: false }
            ]
          },
          {
            title: '日常保健',
            icon: '👥',
            items: [
              { id: 5, title: '美容美颜・刮痧疗法', image: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=300&fit=crop', isFree: true, hasUpload: true },
              { id: 6, title: '强健睡眠・刮痧疗法', image: 'https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=400&h=300&fit=crop', isFree: false }
            ]
          }
        ]
      }
    }
  },

  onLoad(options) {
    console.log('功能页面加载', options)
    
    // 如果有传入的分类参数，设置当前分类
    if (options.category) {
      this.setData({
        currentCategory: options.category
      })
    }
    
    // 设置当前内容
    this.updateCurrentContent()
  },

  // 更新当前显示的内容
  updateCurrentContent() {
    const currentCategory = this.data.currentCategory
    const currentContent = this.data.categoryContent[currentCategory]
    
    this.setData({
      currentContent: currentContent
    })
  },

  // 分类点击事件
  onCategoryTap(e) {
    const categoryType = e.currentTarget.dataset.type
    console.log('分类切换:', categoryType)
    
    this.setData({
      currentCategory: categoryType
    })
    
    this.updateCurrentContent()
  },

  // 内容点击事件
  onContentTap(e) {
    const contentId = e.currentTarget.dataset.id
    console.log('内容点击，ID:', contentId)
    
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    })
  },

  // 返回上一页
  goBack() {
    if (getCurrentPages().length > 1) {
      wx.navigateBack()
    } else {
      wx.switchTab({ url: '/pages/index/index' })
    }
  }
})





